# +
# NOME: zip_envi.py
#
# AUTOR: Joao Siqueira.
#        Instituto do Homem e Meio Ambiente da Amazonia.
#        email: joaovictor@imazon.org.br
#
# PROPOSITO: Compactar em arquivo zipfile as imagens no formato ENVI Standard.
# -

import glob, os.path, time, zipfile

inputPathName  = "F:\\landsat_2000\\1_59\\img\\reg"
outputPathName = "F:\\landsat_2000\\1_59\\img\\reg"

fileName = glob.glob(inputPathName +'\\*.hdr')
print 'Total de imagens:', len(fileName)

t0 = time.clock()
for i in range(0, len(fileName)):
    try:
        (filePath, hdrName) = os.path.split(fileName[i])
        (imgName, extension) = os.path.splitext(hdrName)  
        
        print filePath
        print imgName
        print hdrName
        print imgName + ".zip"
        
        zipFileName = outputPathName +"\\"+ imgName + ".zip"
        
        z = zipfile.ZipFile(zipFileName,'w',zipfile.ZIP_DEFLATED)
        z.write(filePath +"\\"+ imgName, imgName, zipfile.ZIP_DEFLATED)
        z.write(filePath +"\\"+ hdrName, hdrName, zipfile.ZIP_DEFLATED)
        z.close()
    except:
        print filePath +"\\"+ imgName, 'nao foi zipado'

    print "--"
    
t1 = (time.clock()-t0)/60.
print 'Tempo total de: %f minutos' % t1
